#include<iostream>
using namespace std;
#include<cmath>
#include<string>
#include<fstream>

void RK2(double a, double b, int n, double (*func)(double x, double y), double y0, double *y){

	int i;
	double h,K1;
	h = (b-a)/n;
	y[0] = y0;
	for(i=0;i<n;i++){
		K1 = func(a + i*h, y[i]);
		y[i+1] = y[i] + h* func( a + i*h + h/2, y[i] + h/2*K1);
	}
}

double f(double x, double y){
	return 10 - y*y;
}

int main(){

	int i,n=10000;
	double a=0, b=2, h;
	double *y = new double [n+1];
	RK2(a, b, n, f, 0, y);

	h = (b-a)/n;
	ofstream fp("Raindrop.txt");
	for(i=0;i<=n;i++)
		fp<< a+i*h << "\t" << y[i]<<endl;
	fp.close();

	delete [] y;
	return 0;
}
